package xcmg.device.web.logistic;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.service.crm.util.ActionResultUtil;
import xcmg.device.service.logistic.LogisticWayBillService;
import xcmg.device.service.vo.logistic.*;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

/**
 * @Des 物流运费结算接口controller
 * @Date 2021/5/19 14:29
 * @Author wangzhaoyu
 * @Param 
 * @Return 
 */
@RestController
@RequestMapping("/logisticWaybillFee")
public class LogisticWaybillFeeController extends BasicController {
    @Autowired
    private LogisticWayBillService logisticWayBillService;

    /**
     * @Des 获取物流运费结算单列表
     * @Date 2021/5/20 14:33
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/listing")
    @FastMappingInfo(needLogin = true)
    public ActionResult listing(@RequestBody SearchCommonVO<LogisticWaybillFeeListQueryParamVO> condition) throws Exception {
        String orgId = getOrgId();
        PageCommonVO<LogisticWaybillFeeListingResultVO> pageResult = logisticWayBillService.listingLogisticWayBillFees(condition,orgId);
        return ActionResultUtil.successActionResult(pageResult.getPageInfo());
    }

    /**
     * @Des 创建物流运费结算单时选择物流运单接口
     * @Date 2021/5/19 15:57
     * @Author wangzhaoyu
     * @Param [condition]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/waybillsSelect")
    @FastMappingInfo(needLogin = true)
    public ActionResult waybillsSelect(@RequestBody SearchCommonVO<LogisticWayBillListQueryParamVO> condition) throws Exception {
        String orgId = getOrgId();
        PageCommonVO<LogisticWaybillSelectResultVO> result = logisticWayBillService.waybillsSelect(orgId,condition);
        return ActionResultUtil.successActionResult(result.getPageInfo());
    }

    /**
     * @Des 物流运费保存
     * @Date 2021/5/19 16:36
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/save")
    @FastMappingInfo(needLogin = true)
    public ActionResult waybillFeeSave(@RequestBody LogisticWaybillFeeSaveVO saveParam) throws Exception {
        LogisticWaybillFeeSaveVO.HeadInfo headInfo = saveParam.getHeadInfo();
        String id = headInfo.getId();
        String orgId = getOrgId();
        String userId = getUserId();
        String userName = getUserName();
        if(StringUtils.isEmpty(id)){
            logisticWayBillService.saveWayBillFee(saveParam,orgId,userId,userName,0);
        }else{
            logisticWayBillService.updateWayBillFee(saveParam,1);
        }
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 编辑、审核、审批时查看运费结算单信息
     * @Date 2021/5/20 19:22
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/viewInfo")
    @FastMappingInfo(needLogin = true)
    public ActionResult viewInfo(String id) throws Exception {
        LogisticWaybillFeeViewResponseVO result = logisticWayBillService.viewBillFeeInfo(id);
        return ActionResultUtil.successActionResult(result);
    }

    /**
     * @Des 物流运费保存
     * @Date 2021/5/19 16:36
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/submit")
    @FastMappingInfo(needLogin = true)
    public ActionResult waybillFeeSubmit(@RequestBody LogisticWaybillFeeSaveVO saveParam) throws Exception {
        LogisticWaybillFeeSaveVO.HeadInfo headInfo = saveParam.getHeadInfo();
        String id = headInfo.getId();
        String orgId = getOrgId();
        String userId = getUserId();
        String userName = getUserName();
        if(StringUtils.isEmpty(id)){
            logisticWayBillService.saveWayBillFee(saveParam,orgId,userId,userName,1);
        }else{
            logisticWayBillService.updateWayBillFee(saveParam,1);
        }

        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 审核通过
     * @Date 2021/5/20 15:44
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("auditPass")
    @FastMappingInfo(needLogin = true)
    public ActionResult auditPass(@RequestBody LogisticWaybillFeeAuditVO auditVO) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.auditWaybillFee(userId,userName,true,auditVO);
        return ActionResultUtil.successActionResult();
    }
    /**
     * @Des 审核拒绝
     * @Date 2021/5/20 15:44
     * @Author wangzhaoyu
     * @Param []
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("auditReject")
    @FastMappingInfo(needLogin = true)
    public ActionResult auditReject(@RequestBody LogisticWaybillFeeAuditVO auditVO) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.auditWaybillFee(userId,userName,false,auditVO);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 审批通过
     * @Date 2021/5/20 17:17
     * @Author wangzhaoyu
     * @Param [approval]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/approvalPass")
    @FastMappingInfo(needLogin = true)
    public ActionResult approvalPass(@RequestBody LogisticWaybillFeeApprovalVO approval) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.approvalWaybillFee(userId,userName,true,approval);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 审批拒绝
     * @Date 2021/5/20 17:17
     * @Author wangzhaoyu
     * @Param [approval]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @PostMapping("/approvalReject")
    @FastMappingInfo(needLogin = true)
    public ActionResult approvalReject(@RequestBody LogisticWaybillFeeApprovalVO approval) throws Exception {
        String userId = getUserId();
        String userName = getUserName();
        logisticWayBillService.approvalWaybillFee(userId,userName,false,approval);
        return ActionResultUtil.successActionResult();
    }

    /**
     * @Des 查看运费结算单中单个物流单的详情信息
     * @Date 2021/5/21 9:56
     * @Author wangzhaoyu
     * @Param [wayBillId]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/viewWayBillInfo")
    @FastMappingInfo(needLogin = true)
    public ActionResult viewWayBillInfo(String wayBillId){
        FeePageViewWaybillInfoVO viewInfo = logisticWayBillService.feePageViewWaybillInfo(wayBillId);
        return ActionResultUtil.successActionResult(viewInfo);
    }

    /**
     * @Des 打印运费结算单信息
     * @Date 2021/5/22 17:29
     * @Author wangzhaoyu
     * @Param [id]
     * @Return yb.ecp.fast.infra.infra.ActionResult
     */
    @GetMapping("/printFeeInfo")
    @FastMappingInfo(needLogin = true)
    public ActionResult printFeeInfo(String id) throws Exception {
        LogisticWaybillFeePrintVO result = logisticWayBillService.printLogisticBillwayFee(id);
        return ActionResultUtil.successActionResult(result);
    }
}
